﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

using YouHP.Model;
using YouHP.DALFactory;
using YouHP.Utility;
using YouHP.BLL.MedicalGraph;

namespace YouHP.BLL
{
    public class PatientIndicatorBLL
    {
        #region 单件模式
        static PatientIndicatorBLL _Instance;

        public static PatientIndicatorBLL Instance
        {
            get
            {
                if (_Instance == null)
                {
                    _Instance = new PatientIndicatorBLL();
                }
                return _Instance;
            }
        }
        #endregion

        #region 实验室指标记录
        /// <summary>
        /// 取得病人的当前实验室指标列表
        /// </summary>
        public List<IndicatorHistoryInfo> GetCurrentIndicatorList(int prId)
        {
            return DataAccess.PatientIndicatorDAL.GetCurrentIndicatorList(prId);
        }

        public List<IndicatorHistoryInfo> GetIndicatorHistoryList(int prId, int indicatorId, int pageSize, int pageIndex, out int count)
        {
            return DataAccess.PatientIndicatorDAL.GetIndicatorHistoryList(prId, indicatorId, pageSize, pageIndex, out count);     
        }

        public List<IndicatorHistoryInfo> GetIndicatorHistoryList(int prId, int indicatorId)
        {
            int count = 0;
            return DataAccess.PatientIndicatorDAL.GetIndicatorHistoryList(prId, indicatorId, Constants.maxPageSize, 1, out count);
        }

        /// <summary>
        /// 取得病人的某种实验室指标的当前程度
        /// </summary>
        public IndicatorHistoryInfo GetCurrentIndicator(int prId, int indicatorId)
        {
            return DataAccess.PatientIndicatorDAL.GetCurrentIndicator(prId, indicatorId);
        }

        //判断历史记录表中是否已存在病人指定时间对应的记录
        public bool CheckIndicatorHistory(int prId, int indicatorId, DateTime recordDate)
        {
            return DataAccess.PatientIndicatorDAL.CheckIndicatorHistory(prId, indicatorId, recordDate);
        }

        /// <summary>
        /// 添加单条的实验室指标历史记录
        /// </summary>
        public bool AddIndicatorHistory(IndicatorHistoryInfo shInfo)
        {
            return DataAccess.PatientIndicatorDAL.AddIndicatorHistory(shInfo);
        }

        /// <summary>
        /// 根据历史Id获得实验室指标历史记录信息
        /// </summary>
        public IndicatorHistoryInfo GetIndicatorHistory(int prId, int historyId)
        {
            return DataAccess.PatientIndicatorDAL.GetIndicatorHistory(prId, historyId);
        }

        /// <summary>
        /// 修改单条的实验室指标历史记录
        /// </summary>
        public bool UpdateIndicatorHistory(IndicatorHistoryInfo ihInfo)
        {
            return DataAccess.PatientIndicatorDAL.UpdateIndicatorHistory(ihInfo);
        }

        /// <summary>
        /// 根据历史Id删除实验室指标历史记录信息
        /// </summary>
        public bool DeleteIndicatorHistory(int prId, int historyId)
        {
            return DataAccess.PatientIndicatorDAL.DeleteIndicatorHistory(prId, historyId);
        }

        /// <summary>
        /// 批量的实验室指标历史记录提交
        /// </summary>
        public bool AddIndicatorSurvey(List<IndicatorHistoryInfo> ihList)
        {
            return DataAccess.PatientIndicatorDAL.AddIndicatorSurvey(ihList);
        }

        /// <summary>
        /// 获得批量的实验室指标历史记录
        /// </summary>
        public List<IndicatorHistoryInfo> GetIndicatorSurvey(int prId, int surveyId)
        {
            return DataAccess.PatientIndicatorDAL.GetIndicatorSurvey(prId, surveyId);
        }

        /// <summary>
        /// 批量的实验室指标历史记录修改
        /// </summary>
        public bool UpdateIndicatorSurvey(int surveyId, List<IndicatorHistoryInfo> ihList)
        {
            return DataAccess.PatientIndicatorDAL.UpdateIndicatorSurvey(surveyId, ihList);
        }   

        /// <summary>
        /// 根据SurveyId删除实验室指标历史记录信息
        /// </summary>
        public bool DeleteIndicatorSurvey(int prId, int surveyId)
        {
            return DataAccess.PatientIndicatorDAL.DeleteIndicatorSurvey(prId, surveyId);
        }
        #endregion    
    }
}
